﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
using Gpsys.Service;

namespace BankA.Generator
{
    public class MT900Generator : GPSThread
    {
        public bool Stop { get; set; }

        protected override void Run()
        {
            Thread.Sleep(1 * 1000);

            Stop = false;
            string fileName = "[[GUID]].900.txt";
            string folderPath = @"c:\GPS\MsgFromSWIFT";
            string data = @"{1:F01CENAIDJAXXXX0001000013}{2:O9001301120322INDOIDJRAXXX00010000131203221301N}{3:{113:0020}}{4:
:20:[[REFNO]]/900
:21:[[REF]]
:25:523014000990
:32A:120322IDR100000000,00
:72:/OID/120322INDOIDJAAXXX0001000009
-}";
            int counter = 1;

            while (!Stop)
            {
                string newData = data.Replace("[[REF]]", DateTime.Today.ToString("yyMMdd") + counter.ToString().PadLeft(10, '0')).Replace("[[REFNO]]", counter.ToString().PadLeft(10, '0'));

                string newfileName = fileName.Replace("[[GUID]]", Guid.NewGuid().ToString());

                string filePath = Path.Combine(folderPath, newfileName);

                using (StreamWriter fs = new StreamWriter(filePath))
                {
                    fs.WriteLine(newData);
                }

                counter++;

                if (counter % 25 == 0) Thread.Sleep(1000);
            }
        }
    }
}
